package org.example.seat_management.Controller.api;

import org.example.seat_management.Entity.SeatConfig;
import org.example.seat_management.Service.SeatConfigService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/seat-config")
public class SeatConfigController {

    private final SeatConfigService seatConfigService;

    public SeatConfigController(SeatConfigService seatConfigService) {
        this.seatConfigService = seatConfigService;
    }

    @PostMapping
    public Long create(@RequestBody SeatConfig config) {
        return seatConfigService.create(config);
    }

    @PutMapping("/{id}")
    public void update(@PathVariable Long id, @RequestBody SeatConfig config) {
        config.setId(id);
        seatConfigService.update(config);
    }

    @GetMapping("/active/{classroomId}")
    public SeatConfig getActive(@PathVariable Long classroomId) {
        return seatConfigService.getActiveByClassroom(classroomId);
    }

    @GetMapping("/classroom/{classroomId}")
    public List<SeatConfig> listByClassroom(@PathVariable Long classroomId) {
        return seatConfigService.listByClassroom(classroomId);
    }
}


